package com.mproject.adapter;

import java.util.ArrayList;

import android.app.LocalActivityManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;

import com.mproject.activity.R;
import com.mproject.customclass.Message;

public class MessageDetailsAdapter extends ArrayAdapter<Message>{
	private Context context;
	LocalActivityManager manager;
	private ArrayList<Message> msgsList = new ArrayList<Message>();
	Button content_recieve;
	Button content_send;

	public MessageDetailsAdapter(Context context, int textViewResourceId,ArrayList<Message> msgsList)
	{
		super(context, textViewResourceId, msgsList);
		this.context = context;
		this.msgsList = msgsList;
	}

	public int getCount() 
	{
		return this.msgsList.size();
	}

	public Message getItem(int index) 
	{
		return this.msgsList.get(index);
	}

	public View getView(final int position, View convertView, ViewGroup parent) 
	{
		View row = convertView;
		if (row == null) 
		{
			LayoutInflater inflater = (LayoutInflater) this.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			row = inflater.inflate(R.layout.msg_details_row, parent, false);
		}
		
		final Message msg = getItem(position);
		content_recieve = (Button) row.findViewById (R.id.content_recieve);
		content_send = (Button) row.findViewById (R.id.content_send);
		/*LinearLayout ll = (LinearLayout) row.findViewById(R.id.linear_layout);
		ImageView im = (ImageView) row.findViewById(R.id.image_view);
		Button bt = (Button) row.findViewById(R.id.button);*/
		LinearLayout recieve = (LinearLayout) row.findViewById(R.id.linear_layout_recieve);
		LinearLayout send = (LinearLayout) row.findViewById(R.id.linear_layout_send);
		if (msg.isSend() == true) {
			recieve.setVisibility(View.GONE);
			send.setVisibility(View.VISIBLE);
			String mesg=msg.getContent();
			mesg=mesg.replace("%xy","\'" );
			mesg=mesg.replace("%yz","\"" );
			mesg=mesg.replace("%xz","\\" );
			content_send.setText(mesg);
		}
		else {
			send.setVisibility(View.GONE);
			recieve.setVisibility(View.VISIBLE);
			String mesg=msg.getContent();
			mesg=mesg.replace("%xy","\'" );
			mesg=mesg.replace("%yz","\"" );
			mesg=mesg.replace("%xz","\\" );
			content_recieve.setText(mesg);
		}

		return row;
	}

}
